package site.wanjiahao;

public class BinarySearch {

    public static int search(int[] ary, int ele) {
        int begin = 0;
        int end = ary.length;
        // 结束循环
        while (end > begin) {
            int mid = (begin + end) >> 1;
            if (ele > ary[mid]) {
                // 右部分
                begin = mid + 1;
            } else if (ele < ary[mid]) {
                end = mid;
            } else {
                return mid;
            }
        }
        return -1;
    }

}
